package com.haofengsoft.scce.controller;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import com.haofengsoft.scce.adapter.information.InformationAttentionModel;
import com.haofengsoft.scce.db.bean.AttentionItem;
import com.haofengsoft.scce.db.biz.consultation.AttentionItemBiz;
import com.haofengsoft.scce.ui.consultation.DailyLimitBoardFragment;
import com.haofengsoft.scce.ui.consultation.FocusNewFragment;
import com.haofengsoft.scce.ui.consultation.GuestColumnFragment;
import com.haofengsoft.scce.ui.consultation.InvestmentTipsFragment;
import com.haofengsoft.scce.ui.consultation.LiveFragment;
import com.haofengsoft.scce.ui.consultation.MarketOverviewFragment;
import com.haofengsoft.scce.ui.consultation.OptionalStampFragment;
import com.haofengsoft.scce.ui.consultation.StampBeiJingFragment;
import com.haofengsoft.scce.ui.consultation.StampNanJingFragment;
import com.haofengsoft.scce.ui.consultation.StampShangHaiFragment;
import com.haofengsoft.scce.ui.consultation.StampZhongNanFragment;
import com.haofengsoft.scce.ui.consultation.StoneGoldFragment;
import com.haofengsoft.scce.ui.fragment.OptionalFragment;

/**
 * Created by admin on 2015/7/22.
 */
public class AttentionController {
    /**
     * 自选
     */
    public final static int OPTIONAL_STAMP = 1;

    /**
     * 要闻
     */
    public final static int FOCUS_NEWS = 2;
    /**
     * 直播
     */
    public final static int LIVE = 3;
    /**
     * 涨停板
     */
    public final static int DAILY_LIMIT_BOARD = 4;
    /**
     * 点石成金
     */
    public final static int STONE_GOLD = 5;
    /**
     * 行情综述
     */
    public final static int MARKET_OVERVIEW = 6;
    /**
     * 币卡市评
     */
    public final static int STAMP_COMMENT = 7;
    /**
     * 嘉宾专栏
     */
    public final static int GUEST_COLUMN = 8;
    /**
     * 南京
     */
    public final static int STAMP_NANJING = 9;
    /**
     * 中南
     */
    public final static int STAMP_ZHONGNAN = 10;
    /**
     * 上海
     */
    public final static int STAMP_SHANGHAI = 11;
    /**
     * 北京
     */
    public final static int STAMP_BEIJING = 12;
    /**
     * 投资锦囊
     */
    public final static int INVESTMENT_TIPS = 13;
    // 自选 OptionalStampFragment
    // 要闻 FocusNewsFragment
    // 直播 LiveFragment
    // 涨停板 DailyLimitBoardFragment
    // 点石成金 StoneGoldFragment
    // 行情综述 MarketOverviewFragment
    // 币卡市评 StampCommentFragment
    // 嘉宾专栏 GuestColumnFragment
    // 南京 StampNanJingFragment
    // 中南 StampZhongNanFragment
    // 上海 StampShangHaiFragment
    // 北京 StampBeijingFragment
    // 投资锦囊 InvestmentTipsFragment
    private static AttentionController instance = null;
    private Context appContext;

    public static synchronized AttentionController getInstance(Context context) {
        if (instance == null) {
            instance = new AttentionController(context);
        }
        return instance;
    }

    public AttentionController(Context appContext) {
        this.appContext = appContext;
    }

    public boolean handAttention(String json) {
        return false;
    }

    // 获取选中的
    public List<AttentionItem> gainCheckAttentionList() {
        return AttentionItemBiz.getInstance(appContext).gainCheckAttentionList();
    }

    // 获取所有的
    public List<AttentionItem> gainAttentionAll() {
        List<AttentionItem> items = AttentionItemBiz.getInstance(appContext).gainAttentionAll();
        List<AttentionItem> itemList = new ArrayList<AttentionItem>();
        List<AttentionItem> checkList = new ArrayList<AttentionItem>();
        List<AttentionItem> noCheckList = new ArrayList<AttentionItem>();
        for (AttentionItem item : items) {
            if (1 == item.getAttentionChecked()) {
                itemList.add(item);
            } else {
                noCheckList.add(item);
            }
        }
        itemList.addAll(checkList);
        itemList.addAll(noCheckList);
        return itemList;
    }

    // 标注，更改选中，以及排序,没有选中的默认 1000

    public void insertAttentionList(List<AttentionItem> attentionItemList) {
        AttentionItemBiz.getInstance(appContext).insertAttentionList(attentionItemList);
    }

    // 转换
    public List<InformationAttentionModel> convertAttentionList() {
        List<AttentionItem> attentionItems = AttentionItemBiz.getInstance(appContext).gainCheckAttentionList();
        //
        if (attentionItems.size() == 0) {
            AttentionItem itemFocus = new AttentionItem(Long.valueOf(AttentionController.FOCUS_NEWS),
                    AttentionController.FOCUS_NEWS, 1, "要闻", 1, "7*24小时国内和国际新闻播报");
            attentionItems.add(itemFocus);
        }
        List<InformationAttentionModel> modelList = new ArrayList<InformationAttentionModel>();
        for (AttentionItem item : attentionItems) {
            InformationAttentionModel model = new InformationAttentionModel();
            model.setTitle(item.getAttentionName());
            model.setAttentionType(item.getType());
            model.setId(item.getId().intValue());
            switch (item.getId().intValue()) {
                case AttentionController.OPTIONAL_STAMP: {
                    model.setFragment(OptionalStampFragment.newInstance("OptionalStampFragment"));
                    break;
                }
                case AttentionController.FOCUS_NEWS: {
                    model.setFragment(FocusNewFragment.newInstance("FocusNewFragment"));
                    break;
                }
                case AttentionController.LIVE:
                    model.setFragment(LiveFragment.newInstance("LiveFragment"));
                    break;
                case AttentionController.DAILY_LIMIT_BOARD:
                    model.setFragment(DailyLimitBoardFragment.newInstance("DailyLimitBoardFragment"));
                    break;
                case AttentionController.STONE_GOLD:
                    model.setFragment(StoneGoldFragment.newInstance("StoneGoldFragment"));
                    break;
                case AttentionController.MARKET_OVERVIEW:
                    model.setFragment(MarketOverviewFragment.newInstance("MarketOverviewFragment"));
                    break;
                case AttentionController.STAMP_COMMENT:
                    model.setFragment(StampBeiJingFragment.newInstance("StampBeiJingFragment"));
                    break;
                case AttentionController.GUEST_COLUMN:
                    model.setFragment(GuestColumnFragment.newInstance("GuestColumnFragment"));
                    break;
                case AttentionController.STAMP_NANJING:
                    model.setFragment(StampNanJingFragment.newInstance("StampNanJingFragment"));
                    break;
                case AttentionController.STAMP_ZHONGNAN:
                    model.setFragment(StampZhongNanFragment.newInstance("StampZhongNanFragment"));
                    break;
                case AttentionController.STAMP_SHANGHAI:
                    model.setFragment(StampShangHaiFragment.newInstance("StampShangHaiFragment"));
                    break;
                case AttentionController.STAMP_BEIJING:
                    model.setFragment(StampBeiJingFragment.newInstance("StampBeiJingFragment"));
                    break;
                case AttentionController.INVESTMENT_TIPS:
                    model.setFragment(InvestmentTipsFragment.newInstance("InvestmentTipsFragment"));
                    break;
                default:
                    break;
            }
            modelList.add(model);
        }
        return modelList;
    }

}
